import React, { Component, useState } from 'react';
import { connect } from 'react-redux';
// import { stand } from '../../view_public/Add_public';
import { Alert, Button, Modal, Form, Input, Radio, Select, Upload, Table, message } from "antd";
import store from '../../../store';
import { Link } from 'react-router-dom';
import action from "../../../store";
import { UploadOutlined } from '@ant-design/icons';



class index extends React.Component {
    constructor() {
        super();
    }
    render() {
        const layout = {
            labelCol: {
                span: 5,
            },
            wrapperCol: {
                span: 15,
            },
        };
        const tailLayout = {
            wrapperCol: {
                offset: 3,
                span: 15,
            },
        };
        const onFinish = values => {
           

            let list = {
                standardNo: values.standardNo,
                name: values.name,
                temperature: values.temperature,
                remark: values.remark,
                standardFileUrl: values.standardFileUrl[0].uid==1?values.standardFileUrl[0].url:values.standardFileUrl[0].response.message
            }
            this.$axios.post('/manager/api/updateStandardInfo', list).then((res) => {
               
              return  res.status===1?this.props.history.push('/admin/Standard'):null;
            }).catch((err) => {
                console.log(err);

            })
        };

        const onFinishFailed = errorInfo => {
            console.log(errorInfo);
        };
        const data = this.props.stand_EditData[0];
     
        const stand = (val) => {
            const { Option } = Select;
            
            const props = {
                action: 'http://www.bestzc.cn:8080/materials.web/common/api/uploadFile_notId',
                onChange({ file, fileList }) {
                    if (file.status !== 'uploading') {
                     
                        if( fileList.length>1)fileList.splice(0,1);
                        store.dispatch({
                            type: 'STANDARD_UPLOAD',
                            upload_pay: file.response.message,
                        })
                    }
                },
                multiple: false,
            };
            const file_list=this.props.stand_EditData[0];
          
            let defaultFileList=[{ 
                uid:1,
                name:file_list.standardFileUrl,
                status:'done',
                url:file_list.standardFileUrl

            }];
           
            
            const normFile = e => {

                if (Array.isArray(e)) {
                    return e;
                }
                return e && e.fileList;
            };
            const data = val;
            const {TextArea}=Input;
            return <div>
                <div className="add_flex">


                    <Form.Item
                        name="standardNo"
                        label="标准编号:"
                        rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]}
                        initialValue={data.standardNo}
                    >
                        <Input placeholder='请输入标准编号' />
                    </Form.Item>
                    <Form.Item name="name" label="标准名称:" rules={[
                        {
                            required: true,
                            message: '内容不能为空!',
                        },
                    ]}
                        initialValue={data.name}
                    >
                        <Input type="textarea" placeholder='请输入标准名称' />
                    </Form.Item>
                </div>

                <div className='add_flex'>
                    <Form.Item name="temperature" label="适用条件:" rules={[
                        {
                            required: true,
                            message: '内容不能为空!',
                        },
                    ]}
                        initialValue={data.temperature}
                    >
                        <Select placeholder="选择">
                            <Option value='A'>常温</Option>
                            <Option value="B">高温</Option>
                            <Option value="C">低温</Option>
                        </Select>
                    </Form.Item>
                    <Form.Item name="remark" label="简介:" initialValue={data.remark}>
                    <TextArea allowClear autoSize={true} />
                    </Form.Item>

                </div>
                <Form.Item
                    name="standardFileUrl"
                    label="Upload"
                    valuePropName="fileList"
                    getValueFromEvent={normFile}
                    initialValue={defaultFileList}
                
                >
                    <Upload {...props} fileList={defaultFileList}>
                        <Button>
                            <UploadOutlined /> 上传文件
                         </Button>
                    </Upload>
                </Form.Item>
            </div>
        }
        return <div>
            <div style={{ textAlign: 'center', fontSize: 20 }}>
                修改测试标准
            </div>
            <div>
                <Form
                    {...layout}
                    name="basic"
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                >
                    {
                        stand(data)
                    }
                    <Form.Item {...tailLayout}>
                        <Button type="primary" htmlType="submit" style={{ margin: '20px 10px' }}>
                            保存
                    </Button>
                        <Link to='/admin/Standard'><Button type='primary'>返回</Button></Link>
                    </Form.Item>
                </Form>
            </div>

        </div>
    }
}

export default connect(state => ({ ...state.custom }), action.custom)(index);